<?php
// +----------------------------------------------------------------------
// | ThinkPHP
// +----------------------------------------------------------------------
// | Copyright (c) 2008 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
// $Id$

function getModuleAction() {
	// 取得模块和操作名称 如果有伪装 则返回真实的名称
	// 可以在Dispatcher中定义获取规则
	if(!defined('MODULE_NAME')) define('MODULE_NAME',   getModule());       // Module名称
	if(!defined('ACTION_NAME')) define('ACTION_NAME',   getAction());        // Action操作
}

/**
 +----------------------------------------------------------
 * 获得实际的模块名称
 +----------------------------------------------------------
 * @access private
 +----------------------------------------------------------
 * @return string
 +----------------------------------------------------------
 */
function getModule()
{
	$var	=	C('VAR_MODULE');
	$module = isset($_POST[$var]) ? $_POST[$var] : (isset($_GET[$var])? $_GET[$var]:'');
	// 如果 $module 为空，则赋予默认值
	if (empty($module)) $module = C('DEFAULT_MODULE');
	return ucwords($module);
}

/**
 +----------------------------------------------------------
 * 获得实际的操作名称
 +----------------------------------------------------------
 * @access private
 +----------------------------------------------------------
 * @return string
 +----------------------------------------------------------
 */
function getAction()
{
	$var	=	C('VAR_ACTION');
	$action   = isset($_POST[$var]) ? $_POST[$var] : (isset($_GET[$var])?$_GET[$var]:'');
	// 如果 $action 为空，则赋予默认值
	if (empty($action)) $action = C('DEFAULT_ACTION');
	return strtolower($action);
}
Tag::add('app_init','getModuleAction');
?>